package com.acxiom.foodreview.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.acxiom.foodreview.dao.SysUserDao;
import com.acxiom.foodreview.entity.SysUser;
import com.acxiom.foodreview.service.SysUserService;

@Service
public class SysUserServiceImpl implements SysUserService {
	@Autowired
    SysUserDao sysUserDao;

	@Override
	@Transactional
	public Boolean createSysUser(SysUser sysUser) {
		BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
		sysUser.setPassword(encoder.encode(sysUser.getRawPassword().trim()));
		if(sysUserDao.createSysUser(sysUser) > 0) {
			if(sysUserDao.linkSysUserToSysRole(sysUser.getId(),sysUser.getRoles()) > 0) {
				return true;
			}
		}
		return false;
	}

}
